package com.bjtech.web.action.management;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.bjtech.dao.BaseBuildingInfoDao;
import com.bjtech.dao.BaseProjectInfoDao;
import com.bjtech.dao.BaseShareAreaInfoDao;
import com.bjtech.domain.BaseProjectInfo;
import com.bjtech.domain.BaseShareAreaInfo;
import com.bjtech.domain.query.BaseShareAreaInfoQuerySpec;
import com.bjtech.web.action.LyheatBaseAction;

public class BaseShareAreaInfoAction extends LyheatBaseAction {

	private static final long serialVersionUID = 1L;
	private BaseShareAreaInfoDao baseShareAreaInfoDao;
	private BaseProjectInfoDao baseProjectInfoDao;
	private BaseShareAreaInfoQuerySpec selectBean;
	
	private List projList;
	
	private List buidlingList;
	private BaseBuildingInfoDao baseBuildingInfoDao;
	
	private Map tjParam = new HashMap();
	
	public void prepare() throws Exception {

	}
	
	public BaseShareAreaInfoAction() throws Exception{
		model = new BaseShareAreaInfo();
		selectBean = new BaseShareAreaInfoQuerySpec();
	}
	
	public void setBaseShareAreaInfoDao(BaseShareAreaInfoDao baseShareAreaInfoDao) {
		this.baseShareAreaInfoDao = baseShareAreaInfoDao;
	}

	public String execute(){
		return this.list();
	}
	
	public String list(){
		selectBean.queryParamString();
		projList = baseProjectInfoDao.selectEntityList(new BaseProjectInfo(), new BaseShareAreaInfoQuerySpec());
		list = this.baseShareAreaInfoDao.selectEntityPaginatedList(new BaseShareAreaInfo(),selectBean);
		return "list";
	}
	
	public String add(){
		projList = baseProjectInfoDao.selectEntityList(new BaseProjectInfo(), new BaseShareAreaInfoQuerySpec());
		return "edit";
	}
	
	public String save(){
		BaseShareAreaInfo entity = (BaseShareAreaInfo)model;
		entity.setBase_price(entity.getArea_price().multiply(entity.getTwo_percent()));
		
		if(entity.getCal_unit()!=null){
			switch(entity.getCal_unit().intValue()){
			case 1:entity.setCal_price_mwh(entity.getCal_price().doubleValue()*1000);break;
			case 2:entity.setCal_price_mwh(entity.getCal_price().doubleValue());break;
			case 3:entity.setCal_price_mwh(entity.getCal_price().doubleValue()*0.0036);break;
			}
		}
		if(entity.getId()==null){
			baseShareAreaInfoDao.insertEntity(entity);
		}else{
			baseShareAreaInfoDao.updateEntity(entity);
		}
		return "success";
	}
	
	public String edit(){
		projList = baseProjectInfoDao.selectEntityList(new BaseProjectInfo(), new BaseShareAreaInfoQuerySpec());
		model = this.baseShareAreaInfoDao.selectEntity(new BaseShareAreaInfo(),id);
		return "edit";
	}

	public String view(){
		model = this.baseShareAreaInfoDao.selectEntity(new BaseShareAreaInfo(),id);
		buidlingList = this.baseBuildingInfoDao.selectBudilingListByAreaId(id);
		tjParam = this.baseShareAreaInfoDao.selectTjParmForShareArea(id);
		return "view";
	}
	
	public String delete(){
		this.baseShareAreaInfoDao.deleteShareAreaLinkedObjs(id);
		model = this.baseShareAreaInfoDao.deleteEntity(new BaseShareAreaInfo(),id);
		return "success";
	}
	
	public BaseShareAreaInfoQuerySpec getSelectBean() {
		return selectBean;
	}

	public void setSelectBean(BaseShareAreaInfoQuerySpec selectBean) {
		this.selectBean = selectBean;
	}

	public BaseProjectInfoDao getBaseProjectInfoDao() {
		return baseProjectInfoDao;
	}

	public void setBaseProjectInfoDao(BaseProjectInfoDao baseProjectInfoDao) {
		this.baseProjectInfoDao = baseProjectInfoDao;
	}

	public BaseShareAreaInfoDao getBaseShareAreaInfoDao() {
		return baseShareAreaInfoDao;
	}

	public List getProjList() {
		return projList;
	}

	public void setProjList(List projList) {
		this.projList = projList;
	}

	public List getBuidlingList() {
		return buidlingList;
	}

	public void setBuidlingList(List buidlingList) {
		this.buidlingList = buidlingList;
	}

	public BaseBuildingInfoDao getBaseBuildingInfoDao() {
		return baseBuildingInfoDao;
	}

	public void setBaseBuildingInfoDao(BaseBuildingInfoDao baseBuildingInfoDao) {
		this.baseBuildingInfoDao = baseBuildingInfoDao;
	}

	public Map getTjParam() {
		return tjParam;
	}

	public void setTjParam(Map tjParam) {
		this.tjParam = tjParam;
	}
}
